package edu.bbu.commonproject.desktop.gui.view.swing.file.lister.utils;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;

import edu.bbu.commonproject.desktop.gui.view.swing.utils.Design;
import edu.bbu.commonproject.desktop.gui.view.swing.utils.TexturedPanel;

/**
 * The General Dialog.
 */
public class GeneralDialog extends JDialog
{
	/** It initializes ERROR_DIALOG. */
	public static final int ERROR_DIALOG = 0;
	
	/** It initializes WARNING_DIALOG. */
	public static final int WARNING_DIALOG = 1;
	
	/** It initializes ACCEPT_DIALOG. */
	public static final int ACCEPT_DIALOG = 2;
	
	/** The text label. */
	private JLabel textLabel;
	
	/** The OK button. */
	private JButton okButton;
	
	/** The back panel */
	private TexturedPanel backPanel;
	
	/** It initializes WARNING_DIALOG. */
	private int dialogType = ERROR_DIALOG;
	
	/** The message. */
	private String message;

	/**
	 * The constructor.
	 * @param parrentFrame the frame parrent.
	 * @param title the title.
	 * @param message the message.
	 * @param dialogType the dialog type.
	 */
	public GeneralDialog(JFrame parrentFrame, String title, String message, int dialogType)
	{
		super(parrentFrame, true);
		
		this.dialogType = dialogType;
		this.message = message;
		
		this.setTitle(title);
		this.setResizable(false);
		this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		
		setComponents();
		
		this.setLocationRelativeTo(parrentFrame);
	}

	/**
	 * It sets the compontes.
	 */
	private void setComponents()
	{
		Image backImage;
		
		switch(dialogType)
		{
			case ERROR_DIALOG:
			{
				backImage = Design.DIALOG_ERROR;
				
			}break;
			
			case WARNING_DIALOG:
			{
				backImage = Design.DIALOG_WARNING;
				
			}break;
			
			default:
			{
				backImage = Design.DIALOG_ACCEPT;
				
			}break;
		}
		
		backPanel = new TexturedPanel(backImage);
		backPanel.setPreferredSize(new Dimension(400, 125));
		backPanel.setLayout(null);
		
		textLabel = new JLabel(message);
		textLabel.setLocation(100, 25);
		textLabel.setSize(new Dimension(300, 25));
		
		okButton = new JButton("OK");
		okButton.setLocation(275, 88);
		okButton.setSize(new Dimension(120, 30));
		okButton.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent arg0)
			{
				close();
			}
		});
		
		backPanel.add(textLabel);
		backPanel.add(okButton);
		
		this.add(backPanel, BorderLayout.CENTER);
		this.pack();
	}
	
	/**
	 * It closes the frame.
	 */
	private void close()
	{
		this.setVisible(false);
		this.dispose();
	}
	
	/**
	 * It sets the dialog to true.
	 */
	public void showDialog()
	{
		this.setVisible(true);
	}	
}